package externaldata.passageTrainTheorique;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class PassageTrainTheoriquePaginationHandler extends DefaultHandler {

	private int responseCount;
	private int responseStartIndex;
	private int totalCount;
	
	private boolean completed = false;
	
	
	@Override
	public void startElement(String namespaceUri, String localName, String rawName, Attributes attributes) throws SAXException {
		
		if (rawName.equals("PagerInfo")) {
			
			String responseCount = attributes.getValue("ResponseCount");
			String responseStartIndex = attributes.getValue("ResponseStartIndex");
			String totalCount = attributes.getValue("TotalCount");
			
			if (responseCount != null && responseStartIndex != null && totalCount != null) {
				this.responseCount = Integer.parseInt(responseCount);
				this.responseStartIndex = Integer.parseInt(responseStartIndex);
				this.totalCount = Integer.parseInt(totalCount);
				
				completed = true;
			}
		}
	}
	
	public boolean isCompleted() {
		return completed;
	}
	
	public int getResponseCount() {
		if (completed)
			return responseCount;
		else
			return -1;
	}
	
	public int getResponseStartIndex() {
		if (completed)
			return responseStartIndex;
		else
			return -1;
	}
	
	public int getTotalCount() {
		if (completed)
			return totalCount;
		else
			return -1;
	}
}
